package io.arukas.core.audit;

import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * Created by IntelliJ IDEA. <br/>
 * Author: YuXian Niu <br/>
 * Email: niuyuxian@163.com <br/>
 * Create: 2021-08-15 23:23 <br/>
 */
@Component
public class SampleAuditorAware implements AuditorAware<String> {
    @Override
    public Optional<String> getCurrentAuditor() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = authentication.getName();
        return Optional.of(username);
    }
}
